package com.wangp.employee.util;

import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;

/**
 * <p>
 * 第一行简要描述.
 * </p>
 *
 * @author wangping
 * @since 2024-12-18
 */
@NoArgsConstructor
public class Result<T> {
    private int code; // 状态码
    private String message; // 响应消息
    private T data; // 响应数据

    // 构造函数
    public Result(int code, String message, T data) {
        this.code = code;
        this.message = message;
        this.data = data;
    }

    // 成功响应的静态方法
    public static <T> Result<T> success(T data) {
        return new Result<>(200, "成功", data);
    }

    // 认证失败的静态方法
    public static <T> Result<T> authenticationFailed() {
        return new Result<>(403, "认证失败", null);
    }

    // 数据错误的静态方法
    public static <T> Result<T> dataError() {
        return new Result<>(300, "数据错误", null);
    }

    // Getter 和 Setter 方法
    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }
}